package cn.hpclub.server.controller.client;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.core.JFinal;

import cn.hpclub.server.constant.ClientApiConstant;
import cn.hpclub.server.model.MemberOrg;
import cn.hpclub.server.restful.API;
import cn.hpclub.server.util.SystemConfigUtil;

@API("/StoreServer/NewsInfo")
public class StoreNewsInfoController extends BaseClientController<MemberOrg>{

    private static Logger logger             = LoggerFactory.getLogger(StoreNewsInfoController.class);
    private static String noticeTemplateHtml = "/website/notice_list.html";

    /**
     * @Title: GainNewsUrl
     * @Description: 获取通知。数据来源于通知管理模块的新闻资讯 TODO
     *               实际应该根据输入参数获取用户定制的HTML5页面，如没有则立即根据规则生成HTML，但是用户的权限一旦改变，
     *               如何重新生成HTML5页面?
     */
    public void GainNewsUrl(){
        int newsId = getParaToInt(ClientApiConstant.Key.NEWSID);
        int storeMasterId = getParaToInt(ClientApiConstant.Key.STOREMASTERID);

        String hostPrefix = SystemConfigUtil.getSystemConfig().getHostPrefix();
        String contextPath = JFinal.me().getContextPath();

        JSONObject jo = setResponseObj(ClientApiConstant.ResultCode.SUCCESS_CODE, "获得资讯信息成功",
                                       hostPrefix + contextPath + noticeTemplateHtml + "?"
                                               + ClientApiConstant.Key.NEWSID + "=" + newsId + "&"
                                               + ClientApiConstant.Key.STOREMASTERID + "=" + storeMasterId);
        renderText(jo.toString());
    }

}
